import os
import pandas as pd
import random

def toIpv6(num):
    nums = [hex((num >> (112 - i * 16)) & 0xFFFF)[2:] for i in range(8)] 
    return ":".join(nums)
    
df = pd.read_csv('ipv6.CSV',names=['startIp', 'endIp', 'name1', 'name2'],header=None)
df1 = df[df['name1'] == 'CN']  
df2 = df[(df['name1'] != 'CN') & (df['name1'] != '-')]
row1 = df1.iloc[random.randrange(0,len(df1))]
row2 = df2.iloc[random.randrange(0,len(df2))]
row1start = int(row1.values[0])
row1end = int(row1.values[1])
row2start = int(row2.values[0])
row2end = int(row2.values[1])
ip1 = toIpv6(random.randrange(row1start+1,row1end))
ip2 = toIpv6(random.randrange(row2start+1,row2end))
os.system("sudo ./ipv6_tcp "+ip1+" "+ip2)